package com.yunfei.practice_mybatis.web.dao;

import com.yunfei.practice_mybatis.web.dataobject.ZhangyunfeiAccountingRecord;
import org.apache.ibatis.jdbc.SQL;

/**
 * @Author: yunfei
 * @Date: 14:56
 */
public class QueryBuilder {
    public String builderQuery(ZhangyunfeiAccountingRecord accountingRecord) {
        return new SQL() {
            {
                SELECT("id, gmt_created, gmt_modified, record_time, amount, type, category, `desc`");

                FROM("zhangyunfei_accounting_record");
                if (accountingRecord.getGmtCreated()!=null){
                    WHERE("record_Time=#{accountingRecord.gmtCreated}");

                }else if(accountingRecord.getAmount()!=null){
                    WHERE("amount=#{accountingRecord.getAmount}");
                }
                ORDER_BY("id desc");
            }
        }.toString();
    }
}
